package gen.desktop;

import gen.desktop.components.GenByArraysPanel;
import gen.desktop.components.GenBySqlPanel;
import gen.desktop.components.MainMenuBar;

import java.awt.BorderLayout;
import java.awt.Toolkit;
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTabbedPane;
import javax.swing.border.EmptyBorder;

public class MainFrame extends JFrame {

	private static final long serialVersionUID = 1L;
	private JPanel contentPane;
	public GenByArraysPanel genByArraysPanel;
	public GenBySqlPanel genBySqlPanel;
	private MainMenuBar mainMenuBar;
	
	public MainMenuBar getMainMenuBar() {
		return mainMenuBar;
	}

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		Application.Launch();
	}

	/**
	 * Create the frame.
	 */
	public MainFrame() {
		setIconImage(Toolkit.getDefaultToolkit().getImage(MainFrame.class.getResource("/gen/desktop/icons/size32x32/hat.png")));
		setTitle("代码生成器");

		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 729, 467);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		contentPane.setLayout(new BorderLayout(0, 0));
		setContentPane(contentPane);

		mainMenuBar = new MainMenuBar();
		contentPane.add(mainMenuBar, BorderLayout.NORTH);

		JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.TOP);
		contentPane.add(tabbedPane, BorderLayout.CENTER);

		genByArraysPanel = new GenByArraysPanel();
		tabbedPane.addTab("从列表生成代码", null, genByArraysPanel, null);

		genBySqlPanel = new GenBySqlPanel();
		tabbedPane.addTab("从SQL语句生成代码", null, genBySqlPanel, null);

		this.addComponentListener(new ComponentAdapter() {
			public void componentResized(ComponentEvent e) {
				genByArraysPanel.centerDivider();
				genBySqlPanel.centerDivider();
			}
		});
		
		mainMenuBar.loadConnConfigToMenu();
	}

}
